package com.cmfi.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cmfi.domain.PlateChainLineSpeed;
import com.cmfi.service.inter.SpeedMstService;
import com.cmfi.utils.Code;
import com.cmfi.utils.Result;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/api/speedmst")
public class SpeedMstController {
	@Autowired
    private SpeedMstService speedMstService;
    static Logger log = LoggerFactory.getLogger(SpeedMstController.class);
    
    /**
     * {@code GET  /EnergyMst} : get current energy used.
     *
     * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the current energyMst in body.
     */
    @GetMapping("/getcurrentspeed")
    @PreAuthorize("hasAuthority('speedManage')")
    public Result getCurrentSpeed() {
    	log.debug("REST request to get current speed used.");
    	PlateChainLineSpeed current = null;
    	try {
    		current = speedMstService.getCurrentEnergy();
    	} catch (Exception e) {
			log.error("[SpeedMstController][getCurrentSpeed] e:{}", e);
			return new Result(Code.GET_ERR, e.getMessage());
		}
    		return new Result(Code.GET_OK, current);
   }
    
}
